import {defineStore} from 'pinia';
import {getToken, isTokenExpired} from '@/services/auth';

export const useAuthStore = defineStore('auth', {
    state: () => ({
        token: getToken(), // 初始时从 localStorage 获取 token
        isLoggedIn: false,
    }),
    actions: {
        checkToken() {
            if (!this.token || isTokenExpired(this.token)) {
                this.isLoggedIn = false;
                this.token = null;
                storeToken(null); // 删除过期的 token
            } else {
                this.isLoggedIn = true;
            }
        },
    },
});
// 暂时没用到
